home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 17 / CU Amiga Magazine's Super CD-ROM 17 (1997)(EMAP Images)(GB)[!][issue 1997-12].iso / CUCD / Programming / DiceSource / lib / stdio / sprintf.c < prev    next >
C/C++ Source or Header  |  1997-09-09  |  814b  |  55 lines

  1.  
  2. /*
  3.  *  SPRINTF.C
  4.  *
  5.  *    (c)Copyright 1992-1997 Obvious Implementations Corp.  Redistribution and
  6.  *    use is allowed under the terms of the DICE-LICENSE FILE,
  7.  *    DICE-LICENSE.TXT.
  8.  */
  9.  
  10. #include <stdarg.h>
  11. #include <stdio.h>
  12. #include <lib/misc.h>
  13.  
  14. #ifndef HYPER
  15. #define HYPER(x) x
  16. #endif
  17.  
  18. static unsigned int
  19. _swrite(buf, n1, n2, sst)
  20. char *buf;
  21. size_t n1;
  22. size_t n2;
  23. const char **sst;
  24. {
  25.     size_t n;
  26.  
  27.     if (n1 == 1)
  28.     n = n2;
  29.     else if (n2 == 1)
  30.     n = n1;
  31.     else
  32.     n = n1 * n2;
  33.  
  34.     _slow_bcopy(buf, *sst, n);
  35.     *sst += n;
  36.     return(n2);
  37. }
  38.  
  39. int
  40. HYPER(sprintf)(buf, ctl, ...)
  41. char *buf;
  42. const char *ctl;
  43. {
  44.     char *ptr = buf;
  45.     int error;
  46.     va_list va;
  47.  
  48.     va_start(va, ctl);
  49.     error = _pfmt(ctl, va, _swrite, &ptr);
  50.     va_end(va);
  51.     *ptr = 0;
  52.     return(error);      /*  count/error */
  53. }
  54.  
  55.